import dayjs from 'dayjs'
import {
  request,
  baseUrl
} from '../../utils/request'

export const loginByCode = (code) => {
  return request({
    url: `/alumnia/user/wx/openid?code=${code}`,
    method: 'GET'
  })
}


export const decryptCode = (data) => {
  return request({
    url: `/alumnia/user/wx/decrypt`,
    method: 'POST',
    data
  })
}

export const getUserInfo = (id) => {
  return request({
    url: '/alumnia/user',
    method: "GET",
    data: {
      openId: id
    }
  })
}
export const updateUserInfo = (userInfo) => {
  return request({
    url: '/alumnia/user',
    method: "PUT",
    data: userInfo
  })
}
export const addUserInfo = (userInfo) => {
  return request({
    url: '/alumnia/user',
    method: "POST",
    data: userInfo
  })
}
export const getMyActivityList = (openid) => {
  return request({
    url: '/alumnia/activity/app/myList',
    method: 'GET',
    data: {
      openid
    }
  })
}
export const getMyAssociationList = (openid) => {
  return request({
    url: '/alumnia/association/app/myList',
    method: 'GET',
    data: {
      openid,
      status: 1
    }
  })
}
export const uploadFile = (filePath) => {
  return new Promise((resolve, reject) => {
    wx.uploadFile({
      url: baseUrl + '/common/upload', // 开发者服务器的URL
      filePath: filePath,
      name: 'file', // 必填，文件对应的 key
      success(res) {
        resolve(res)
      },
      fail(err) {
        reject(err)
      }
    })
  })

}